package components;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.JPanel;

public class GraphPanel extends JPanel {
	
	private ArrayList<LinguisticVariable> variables = null;
	private int selectedVariableIndex = 0;
	
	public GraphPanel(  ArrayList<LinguisticVariable> variables ){
		this.variables = variables;
	}
	
	public void redraw( int selectedVariableIndex ) {
		this.selectedVariableIndex = selectedVariableIndex;
		repaint();
	}
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		if( variables.size()>0 ){
			Rectangle rec = g.getClipBounds();
			g.clearRect(0, 0, (int)rec.getMaxX(), (int)rec.getMaxY() );
			variables.get(selectedVariableIndex).drawGraph(g);		
		}		
	}
	
}
